/**
 * Copyright (c) 2014 zhenrongbao.com, Inc. All Rights Reserved
 * @author: jiangshuguang
 * @Date  : 14-11-11
 * @Time  : 下午9:13
 * @brief :
 */
(function () {
    var Pagination = require('common:widget/ui/pagination/pagination.js').Pagination,
        util = require('common:widget/ui/libs/util.js').util,
        $page = $('.page-sysrecord'),
        pMap = {
            1:'活期',
            2:'定期(30天)',
            3:'定期(90天)'
        };

    P.createPage({
        _data:{
            type : 1,
            status : 0
        },

        _create:function(){
            var me = this,
                pagination = new Pagination({
                    container:$page.find('.record-pagination'),
                    perCount:10,
                    cur:1,
                    onRefresh:function(curPage,callback){
                        $.getJSON('/user/systemloglist',{
                            type : me.data('type'),
                            status : me.data('status'),
                            current_page:curPage
                        },function(ret,status){
                            if(ret.error_no == 0 && ret.data){
                                callback(ret.data.page_count*10);
                                me._createTableList(ret.data.trade_list);
                            }
                        });
                    }
                });
            this.data('pagination',pagination);
        },

        _init:function(){
            var me = this;
            $page.find('.time_scope li').click(function(){
                $(this).siblings().removeClass('btn-main');
                $(this).addClass('btn-main');
                me.data('type',$(this).attr('data-type'));
                me.refresh();
            });

        },

        //更新数据
        refresh:function(){
            var pagination = this.data("pagination");
            $page.find('.list-table tbody').html('');
            pagination.initPage(1);
        },

        //生成表格内容
        _createTableList:function(list){
            $page.find('.list-table tbody').html((function(){
                var html = "";
                $.each(list,function(k,v){
                    html+='' +
                        '<tr>' +
                        '<td>'+ v.serial_id+'</td>' +
                        '<td>'+pMap[v.pid]+'</td>' +
                        '<td>'+ util.toTime(v.timestamp*1000,'yyyy-MM-dd hh:mm:ss')+'</td>' +
                        '<td>'+(v.type==1?"买入":"卖出")+'</td>' +
                        '<td>￥'+ mathUtil.formatAmount(v.amount)+'</td>' +
                        '<td>'+ v.fee+'</td>' +
                        '<td>'+ (v.profit?'￥'+mathUtil.formatAmount(v.profit):'')+'</td>' +
                        '<td>交易成功</td>' +
                        '</tr>' +
                        ''
                });
                return html;
            })());
        }
    });
})();